var animationId;
function animate() {
    // 动画逻辑
    if (/* 某个条件 */) {
        cancelAnimationFrame(animationId); // 停止动画
    } else {
        animationId = requestAnimationFrame(animate);
    }
}
animationId = requestAnimationFrame(animate);
